<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <style type="text/css">
        .header {
            padding: 2.5rem 0.5rem 2rem 0.5rem;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="padding-top:25px;padding-top:1.1rem;">
        <a class="aui-pull-left aui-btn" onclick="closeWin()"></a>
        <div class="aui-title">E文通</div>
        <a class="aui-pull-rsight aui-btn"></a>
    </header>
  <div class="head-d"></div>
    <div id="list"></div>
<div class="menu-d"></div>

    <div class="index">

        <div id="list2">
        </div>

    </div>




    <!-- <div class="foot-t"></div>
<ul class="foot">
  <li class="active">
    <i class="aui-iconfont aui-icon-home"></i>
    <p>首页</p>
  </li>
  <li>
    <i class="aui-iconfont aui-icon-my"></i>
    <p>我的</p>
  </li>
</ul> -->

</body>

<script type="text/template" id="template">
    <div class="menu">
        <ul>
            {{~it:value:index}}
            <!-- <li class="active">分类二</li> -->
            <li id="type{{=value.id}}" class="li_index" onclick="changeType({{=value.id}});" style="text-align:center">{{=value.name}}</li>
            {{~}}
        </ul>
    </div>
</script>

<script type="text/template" id="template2">


    {{~it:value:index}}
    <!-- <li onclick="readCon('{{=value.id}}','{{=value.end_time}}','{{=value.user_id}}','{{=value.user_name}}','{{=value.number}}');">
        <p>{{=value.number}}  {{=value.name}} {{? value.red_head==1}}
            <i class="aui-bg-danger">红头</i> {{??}}{{?}} {{? value.grade==1}}
            <i class="aui-bg-primary">{{=value.grade}}级文件</i> {{?? value.grade==2}}
            <i class="aui-bg-success">{{=value.grade}}级文件</i> {{?? value.grade==3}}
            <i class="aui-bg-info">{{=value.grade}}级文件</i> {{??}} {{?}} {{? value.secret==1}}
            <i class="aui-bg-primary">{{=value.secret}}级机密</i> {{?? value.secret==2}}
            <i class="aui-bg-success">{{=value.secret}}级机密</i> {{?? value.secret==3}}
            <i class="aui-bg-info">{{=value.secret}}级机密</i> {{??}} {{?}}
        </p>
        <span id="create_time">{{=value.create_time}}</span>
    </li> -->
    <!-- <dl>
        <dt>人事发【2019】X号<span>2018-11-20</span></dt>
        <dd>文章标题文章标题文章标题文章标题</dd>
        <p><i class="aui-bg-danger">红头</i><i class="aui-bg-primary">1级文件</i><i class="aui-bg-primary">1级文件</i></p>
    </dl> -->

    <dl onclick="readCon('{{=value.id}}','{{=value.end_time}}','{{=value.user_id}}','{{=value.user_name}}','{{=value.number}}');">
        <dt>{{=value.number}}<span id="create_time">{{=value.create_time}}</span></dt>
        <dd>{{=value.name}}</dd>
        <p>{{? value.red_head==1}}
            <i class="aui-bg-danger">红头</i> {{??}}{{?}} {{? value.grade==1}}
            <i class="aui-bg-primary">{{=value.grade}}级文件</i> {{?? value.grade==2}}
            <i class="aui-bg-success">{{=value.grade}}级文件</i> {{?? value.grade==3}}
            <i class="aui-bg-info">{{=value.grade}}级文件</i> {{??}} {{?}} {{? value.secret==1}}
            <i class="aui-bg-primary">秘密</i> {{?? value.secret==2}}
            <i class="aui-bg-success">机密</i> {{?? value.secret==3}}
            <i class="aui-bg-info">绝密</i> {{??}} {{?}}
        </p></p>
    </dl>
    {{~}}


</script>

<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
    var typeid = '';
    var page = 0;
    var p = 0;

    function openClub() {
        var delay = 0;
        if (api.systemType != 'ios') {
            delay = 300;
        }
        api.openWin({
            name: 'club_win',
            url: './html/club_win.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    }

    function closeWin() {
        api.closeWin({});
    }

    apiready = function() {

        updateData();
        addObserver();
        down_refresh();
        getPagesign();

    }

    function getPagesign()
    {
      var ajpush = api.require('ajpush');
      if (api.systemType == "ios") {//苹果通知
						api.addEventListener({
							name : 'noticeclicked'
						}, function(ret, err) {

							if (ret && ret.value) {
                // alert( JSON.stringify( ret ) );
								var ajpush = ret.value;
                var extra = ajpush.extra
								var pageSign = ajpush.extra.pageSign;
                var i_id = ajpush.extra.i_id;
                var au_id = ajpush.extra.au_id;

                if (pageSign==1) {
                    api.openWin({
                        name: 'content',
                        url: './content.html',
                        scaleEnabled:true,
                        pageParam: {
                            id: i_id
                        }
                    });
                }else if(pageSign==2){

                  api.openWin({
                      name: 'approval_details',
                      url: './approval_details.html',
                      scaleEnabled:true,
                      pageParam: {
                          id: au_id
                      }
                  });
                }
								//alert("苹果通知："+"id=" + id + ",title=" + title + ",content=" + content + ",extra=" + extra);
							}
						})
					}else{
          api.addEventListener({
              name: 'appintent'
          }, function(ret, err) {
              var ret = ret;
              var pageSign = ret.appParam.ajpush.extra.pageSign;
              var i_id = ret.appParam.ajpush.extra.i_id;
              var au_id = ret.appParam.ajpush.extra.au_id;

              if (pageSign==1) {
                  api.openWin({
                      name: 'content',
                      url: './content.html',
                      scaleEnabled:true,
                      pageParam: {
                          id: i_id
                      }
                  });
              }else if(pageSign==2){
                // alert( JSON.stringify( au_id ) );
                api.openWin({
                    name: 'approval_details',
                    url: './approval_details.html',
                    scaleEnabled:true,
                    pageParam: {
                        id: au_id
                    }
                });
              }
          })
        }
    }

    function updateData() {
        var userid = $api.getStorage('id');
        api.ajax({
            url: 'http://oa.big-wealth.com/index.php?m=&c=SystemFolder&a=index_api&api_auth_id=' + userid,
            method: 'get',
        }, function(ret, err) {
            if (ret) {
                // alert( JSON.stringify( ret ) );
                typeid = ret.date[0].id;
                templateFun(ret.date);

            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    function templateFun(data) {
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);

        $("#type" + typeid).addClass("active");
        updateData2();
    }

    function updateData2(n) {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });


        var userid = $api.getStorage('id');
        if (n) {
            page += 1;
        } else {
            page = 1;
        }
        var url = 'http://oa.big-wealth.com/index.php?m=&c=info&a=my_info_api&api_auth_id=' + userid + '&f_id=' + typeid + '&p=' + page;
// console.log(url);
        api.ajax({
            url: url,
            method: 'get',

        }, function(ret, err) {
            if (ret) {
                  // alert( JSON.stringify( ret ) );
                if (!ret.data) {
                    api.toast({
                        msg: '没有内容！',
                        duration: 1500,
                        location: 'middle'
                    });
                    templateFun2(null);
                    api.refreshHeaderLoadDone();
                    api.hideProgress();
                    return;
                }
                // for (var i = 0; i < ret.data.length; i++) {
                //     var index = getDate(ret.data[i].create_time).search(' ')
                //     ret.data[i].create_time = getDate(ret.data[i].create_time).substr(0, index);
                // }
                p = ret.yema;

                templateFun2(ret.data);
                api.refreshHeaderLoadDone();
                api.hideProgress();

            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    function templateFun2(data) {
        var template = $api.byId('template2');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list2');
        if (page == 1) {
            $api.html(list, html);
        } else {

            if (!data) {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(list, html);
        }
        // console.log(14);
    }

    function changeType(id) {
        var li_id = 'type' + id;
        $(".li_index").removeClass("active");
        $("#" + li_id).addClass('active');
        typeid = id;
        updateData2();
    }

    function readCon(id, end_time, user_id, name, num) {

        api.openWin({
            name: 'content',
            url: './content.html',
            scaleEnabled:true,
            pageParam: {
                id: id,
                // typeid: typeid,
                end_time: end_time,
                sender_id: user_id,
                name: name,
                num: num
            }
        });

    }

    // 下拉刷新
    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            page = 1;

            updateData2();
        });
    }

    // 上拉加载
    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {

            if (p <= page) {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }

            updateData2(true);
        });
    }
</script>

</html>
